package main

import (
	"bufio"
	"fmt"
	"hwanginsitein/network"
	"net"
	"os"
	"strings"
	"encoding/json"
)

const connectType = network.Network
const port = network.Port
const connectAddress = network.Address + ":" + port

func main() {
	conn, err := net.Dial(connectType, connectAddress)
	defer conn.Close()
	if err != nil {
		fmt.Println(err)
	}
	inputReader := bufio.NewReader(os.Stdin)
	for {
		line, readErr := inputReader.ReadString('\n')
		if readErr != nil {
			fmt.Print(readErr)
			return
		}
		line = strings.Trim(line, "\r\n")
		dataStruct := network.Data{
			UserId:0,
			Token:"",
			Step:0,
			BodyData:line,
		}
		data,_ := json.Marshal(dataStruct)
		fmt.Println(string(data))
		n, sendErr := conn.Write(data)
		if sendErr != nil {
			fmt.Println(sendErr)
			return
		}
		fmt.Printf("已经发送了 %d bytes数据 \n", n)
	}
}

